package com.epoint.mobileoa.personalized.epointcompany.ui;

import java.util.HashMap;
import java.util.List;

import android.content.DialogInterface;
import android.content.Intent;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.Task;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.BtnAddBaoxiaoDetailTask;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.DeleteBaoxiaomingxiTask;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.GetCCQKTask;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.GetChuchaibaoxiaomingxiTask;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.GetRZTXInfo;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.GetRiziNeirongTask;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.SaveRizhiTask;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.SummitRizhiTask;
import com.epoint.mobileoa.personalized.epointcompany.model.ChuchaibaoxiaomingxiModel;
import com.epoint.mobileoa.personalized.epointcompany.model.GongzuoRzBaoxiaoModel;
import com.epoint.mobileoa.personalized.epointcompany.model.GongzuoRzDetailModel;
import com.epoint.mobileoa.personalized.epointcompany.model.GongzuomingxiModel;
import com.epoint.mobileoa.personalized.epointcompany.model.RZCheckHistoryMedel;
import com.epoint.mobileoa.service.MainService;
import com.epoint.mobileoa.tools.AlertHelp;
import com.epoint.mobileoa.tools.ControlsHelp;
import com.epoint.mobileoa.tools.LogHelp;
import com.epoint.mobileoa.tools.StringHelp;
import com.epoint.mobileoa.tools.ToastHelp;
import com.epoint.mobileoa.ui.personchoose.PersonChooseViewNew;

/**
 * @author liyc
 * @time 2012-3-22 下午2:46:32
 * @annotation 工作日志填写
 */
public class RZTianxieView extends SuperView {

	private Button btGzlr, btDrfy, btRznr, btCcqk, btLyqk, btQjqk;

	private int taskid = 1;// 1日志内容(已审) 2出差情况
							// 3日志填写内容（任务信息）4.保存当日费用餐费,5获取出差报销明细,6日志提交,7日志提交,8删除报销明细

	private RelativeLayout rl_rizhidetail, layoutRizhineirong,
			epointcompany_ccqk, epoint_gzrztx;

	private LayoutInflater inflater;
	private String shzt;
	private String cczt;
	private String ldps;
	private String rzdate;
	private String psryname;
	private String gzrzguid = "";
	private String ccguid = "";
	private String psdate = "";
	private LinearLayout llGzmx, llDpls;

	private String addresscode = "";// 出差地区code
	private String addressname = "";// 出差地区名称

	private List<GongzuoRzDetailModel> gzrzdlist;
	private ListView drgzmxlv;
	private String[] sj = new String[] { "00:00", "00:30", "01:00", "01:30",
			"02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00",
			"05:30", "06:00", "06:30", "07:00", "07:30", "08:00", "08:30",
			"09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00",
			"12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30",
			"16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00",
			"19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30",
			"23:00", "23:30" };

	private int resumeType;// 1用餐人员中餐,2用餐人员晚餐,3新增工作,4出差报销明细
	private int serverDateInt, clickdate;

	@Override
	public void initControls() {

		inflater = LayoutInflater.from(this);

		rl_rizhidetail = (RelativeLayout) findViewById(R.id.rl_rizhidetail);
		// rl_rizhidetail2 = (RelativeLayout)
		// findViewById(R.id.rl_rizhidetail2);

		shzt = getIntent().getStringExtra("shzt");
		cczt = getIntent().getStringExtra("cczt");
		ldps = getIntent().getStringExtra("ldps");
		rzdate = getIntent().getStringExtra("rzdate");
		psryname = getIntent().getStringExtra("psryname");
		gzrzguid = getIntent().getStringExtra("gzrzguid");
		ccguid = getIntent().getStringExtra("ccguid");
		System.out.println(ccguid);

		psdate = getIntent().getStringExtra("psdate");
		serverDateInt = getIntent().getIntExtra("serverDateInt", 0);
		clickdate = getIntent().getIntExtra("clickdate", 0);

		if (shzt.equals("已审") || shzt.equals("评审结果")) {
			btRznr = (Button) findViewById(R.id.btRznr);
			btRznr.setOnClickListener(this);
			btRznr.setVisibility(View.VISIBLE);
			Rizineirong();
		} else {
			btGzlr = (Button) findViewById(R.id.btGzlr);
			btGzlr.setOnClickListener(this);
			btGzlr.setVisibility(View.VISIBLE);
			gzrizhitianxie();
		}

		// if(cczt.equals("出差")){
		// if(!shzt.equals("已审")&&!shzt.equals("评审结果")){
		// btDrfy = (Button) findViewById(R.id.btDrfy);
		// btDrfy.setOnClickListener(this);
		// btDrfy.setVisibility(View.VISIBLE);
		// // drfy();
		// }
		// }
		if (cczt.equals("旅游")) {
			btLyqk = (Button) findViewById(R.id.btLyqk);
			btLyqk.setOnClickListener(this);
			btLyqk.setVisibility(View.VISIBLE);
			// lyqk();
		} else if (cczt.equals("请假")) {
			btQjqk = (Button) findViewById(R.id.btQjqk);
			btQjqk.setOnClickListener(this);
			btQjqk.setVisibility(View.VISIBLE);
			// qjqk();
		}

		if (!shzt.equals("已审") && !shzt.equals("评审结果")) {
			btDrfy = (Button) findViewById(R.id.btDrfy);
			btDrfy.setOnClickListener(this);
			btDrfy.setVisibility(View.VISIBLE);
			// drfy();
		}
	}

	// 请假情况
	private void qjqk() {

		rl_rizhidetail.removeAllViews();
	}

	private void Rizineirong() {

		rl_rizhidetail.removeAllViews();

		top_title.setText("日志明细");

		layoutRizhineirong = (RelativeLayout) inflater.inflate(
				R.layout.epointcompany_rizhineirong, null);
		
		EditText etGZSJ = (EditText) layoutRizhineirong
				.findViewById(R.id.etGZSJ);
		etGZSJ.setText(rzdate.substring(0, 10));

		EditText etPSLR = (EditText) layoutRizhineirong
				.findViewById(R.id.etPSLR);
		etPSLR.setText(ldps);

		EditText etPSRY = (EditText) layoutRizhineirong
				.findViewById(R.id.etPSRY);
		etPSRY.setText(psryname);

		EditText etPSRQ = (EditText) layoutRizhineirong
				.findViewById(R.id.etPSRQ);
		etPSRQ.setText(psdate);

		TextView worktime_tv = (TextView) layoutRizhineirong.findViewById(R.id.tvRizhineirong);
		setTextViewFontColor(worktime_tv);
		
		TextView tvRizhineirong_psyj = (TextView) layoutRizhineirong.findViewById(R.id.tvRizhineirong_psyj);
		setTextViewFontColor(tvRizhineirong_psyj);
		
		TextView tvRizhineirong_psry = (TextView) layoutRizhineirong.findViewById(R.id.tvRizhineirong_psry);
		setTextViewFontColor(tvRizhineirong_psry);
		
		TextView tvRizhineirong_psrq = (TextView) layoutRizhineirong.findViewById(R.id.tvRizhineirong_psrq);
		setTextViewFontColor(tvRizhineirong_psrq);
		
		rl_rizhidetail.addView(layoutRizhineirong);
		getRiziNeirong();

		if (cczt.equals("出差")) {
			btCcqk = (Button) findViewById(R.id.btCcqk);
			btCcqk.setOnClickListener(this);
			btCcqk.setVisibility(View.VISIBLE);
		}

	}

	// 出差情况
	private void ccqk() {

		showDialog_wait(null);

		taskid = 2;
		rl_rizhidetail.removeAllViews();

		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("ccguid", ccguid);
		param.put("rzdate", rzdate);
		param.put("gzrzguid", gzrzguid);
		Task task = new GetCCQKTask(this, param);
		MainService.addTask(task);
	}

	private void getRiziNeirong() {

		showDialog_wait(null);

		taskid = 1;
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("gzrzguid", gzrzguid);
		Task task = new GetRiziNeirongTask(this, map);
		MainService.addTask(task);

	}

	@Override
	public void refresh(Object... param) {
		m_Dialog.dismiss();
		top_pb.setVisibility(View.GONE);
		if (param[0].toString().equals(MainService.NORMAL)) {
			if (taskid==1) {
				llGzmx = (LinearLayout) layoutRizhineirong
						.findViewById(R.id.llGzmx);
				llDpls = (LinearLayout) layoutRizhineirong
						.findViewById(R.id.llDpls);
				String bs = param[1].toString();
				String gzmxStr = StringHelp.getXMLAttOut(bs, "gzmxs");
				String dplsStr = StringHelp.getXMLAttOut(bs, "dplss");

				List<GongzuomingxiModel> list = GetRiziNeirongTask
						.XmlAnalysis(gzmxStr);
				List<RZCheckHistoryMedel> dplsList = GetRiziNeirongTask
						.dplsXmlAnalysis(dplsStr);

				if (list.size() > 0) {

					LinearLayout ggmx_ll_title = (LinearLayout) inflater
							.inflate(R.layout.gzmx_ll, null);

					layoutRizhineirong.findViewById(R.id.tvGZMXTAG)
							.setVisibility(View.VISIBLE);

					TextView tvGZLB_title = (TextView) ggmx_ll_title
							.findViewById(R.id.tvGZLB);
					tvGZLB_title.setText(Html
							.fromHtml("<font color="+getYGColor()+">类别</font>"));
					TextView tvXMMC_title = (TextView) ggmx_ll_title
							.findViewById(R.id.tvXMMC);
					tvXMMC_title.setText(Html
							.fromHtml("<font color="+getYGColor()+">项目名称</font>"));
					TextView tvRWMC_title = (TextView) ggmx_ll_title
							.findViewById(R.id.tvRWMC);
					tvRWMC_title.setText(Html
							.fromHtml("<font color="+getYGColor()+">任务名称</font>"));
					TextView tvGS = (TextView) ggmx_ll_title
							.findViewById(R.id.tvGS);
					tvGS.setText(Html.fromHtml("<font color="+getYGColor()+">工时</font>"));

					llGzmx.addView(ggmx_ll_title);
				}

				for (int i = 0; i < list.size(); i++) {
					final GongzuomingxiModel zm = list.get(i);
					LinearLayout ggmx_ll = (LinearLayout) inflater.inflate(
							R.layout.gzmx_ll, null);
					/*
					 * StringBuilder sb = new StringBuilder();
					 * sb.append("<font color=#FF0000>"+zm.TypeName+"</font>" +
					 * "&nbsp<font color=white>"+zm.XiangMuMC+"</font>" +
					 * "&nbsp<font color=#FF0000>"+zm.MissionName+"</font>");
					 */
					TextView tvGZLB = (TextView) ggmx_ll
							.findViewById(R.id.tvGZLB);
					setTextViewFontColor(tvGZLB);
					tvGZLB.setText(zm.TypeName);
					TextView tvXMMC = (TextView) ggmx_ll
							.findViewById(R.id.tvXMMC);
					setTextViewFontColor(tvXMMC);
					tvXMMC.setText(zm.XiangMuMC.equals("")?"<空>":zm.XiangMuMC);
					TextView tvRWMC = (TextView) ggmx_ll
							.findViewById(R.id.tvRWMC);
					setTextViewFontColor(tvRWMC);
					tvRWMC.setText(zm.MissionName.equals("")?"<空>":zm.MissionName);
					TextView tvGS_title = (TextView) ggmx_ll
							.findViewById(R.id.tvGS);
					setTextViewFontColor(tvGS_title);
					tvGS_title.setText(zm.GongZuoSJ);

					llGzmx.addView(ggmx_ll);

					ggmx_ll.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							AlertHelp.ShowAlert(RZTianxieView.this, "【工作类别】"
									+ zm.TypeName + "\n【项目名称】" + zm.XiangMuMC
									+ "\n【任务名称】" + zm.MissionName + "\n【工作时间】"
									+ zm.GongZuoSJ + "\n【核准工时】"
									+ zm.CheckWorkSJ + "\n【加班工时】"
									+ zm.ExtraWorkSJ + "\n【核准加班工时】"
									+ zm.ExtreaStandardSJ + "\n【完成比例】"
									+ zm.CompletePercent + "%" + "\n【工作内容】"
									+ zm.GongZuoNR);
						}
					});
				}

				if (dplsList.size() > 0) {
					LinearLayout ggmx_ll_title = (LinearLayout) inflater
							.inflate(R.layout.dpls_ll, null);
					layoutRizhineirong.findViewById(R.id.tvDPLSTAG)
							.setVisibility(View.VISIBLE);
					TextView tvGZLB_title = (TextView) ggmx_ll_title
							.findViewById(R.id.tvGZLB);
					tvGZLB_title.setText(Html
							.fromHtml("<font color="+getYGColor()+">序号</font>"));
					TextView tvXMMC_title = (TextView) ggmx_ll_title
							.findViewById(R.id.tvXMMC);
					tvXMMC_title.setText(Html
							.fromHtml("<font color="+getYGColor()+">点评日期</font>"));
					TextView tvRWMC_title = (TextView) ggmx_ll_title
							.findViewById(R.id.tvRWMC);
					tvRWMC_title.setText(Html
							.fromHtml("<font color="+getYGColor()+">点评人</font>"));
					TextView tvGS = (TextView) ggmx_ll_title
							.findViewById(R.id.tvGS);
					tvGS.setText(Html
							.fromHtml("<font color="+getYGColor()+">点评内容</font>"));

					llDpls.addView(ggmx_ll_title);
				}

				for (int i = 0; i < dplsList.size(); i++) {
					final RZCheckHistoryMedel zm = dplsList.get(i);
					LinearLayout ggmx_ll = (LinearLayout) inflater.inflate(
							R.layout.dpls_ll, null);
					TextView tvGZLB = (TextView) ggmx_ll
							.findViewById(R.id.tvGZLB);
					setTextViewFontColor(tvGZLB);
					tvGZLB.setText(zm.xh);
					TextView tvXMMC = (TextView) ggmx_ll
							.findViewById(R.id.tvXMMC);
					setTextViewFontColor(tvXMMC);
					tvXMMC.setText(zm.dprq);
					TextView tvRWMC = (TextView) ggmx_ll
							.findViewById(R.id.tvRWMC);
					setTextViewFontColor(tvRWMC);
					tvRWMC.setText(zm.dpr);
					TextView tvGS_title = (TextView) ggmx_ll
							.findViewById(R.id.tvGS);
					setTextViewFontColor(tvGS_title);
					tvGS_title.setText(zm.dplr);

					llDpls.addView(ggmx_ll);

					ggmx_ll.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							AlertHelp.ShowAlert(RZTianxieView.this, "【序号】"
									+ zm.xh + "\n【点评日期】" + zm.dprq + "\n【点评人】"
									+ zm.dpr + "\n【点评内容】" + zm.dplr);
						}
					});
				}
			} else if (taskid == 2) {

				epointcompany_ccqk = (RelativeLayout) inflater.inflate(
						R.layout.epointcompany_ccqk, null);

				EditText etCCDQ = (EditText) epointcompany_ccqk
						.findViewById(R.id.etCCDQ);
				EditText etCCXXDZ = (EditText) epointcompany_ccqk
						.findViewById(R.id.etCCXXDZ);
				EditText etCCQZSJ = (EditText) epointcompany_ccqk
						.findViewById(R.id.etCCQZSJ);
				EditText etSYCL = (EditText) epointcompany_ccqk
						.findViewById(R.id.etSYCL);
				EditText etCCSJ = (EditText) epointcompany_ccqk
						.findViewById(R.id.etCCSJ);
				EditText etBT = (EditText) epointcompany_ccqk
						.findViewById(R.id.etBT);
				EditText etYCRYZC = (EditText) epointcompany_ccqk
						.findViewById(R.id.etYCRYZC);
				EditText etYCKHZC = (EditText) epointcompany_ccqk
						.findViewById(R.id.etYCKHZC);
				EditText etGZBCFYZC = (EditText) epointcompany_ccqk
						.findViewById(R.id.etGZBCFYZC);
				EditText etYCRYWC = (EditText) epointcompany_ccqk
						.findViewById(R.id.etYCRYWC);
				EditText etYCKHWC = (EditText) epointcompany_ccqk
						.findViewById(R.id.etYCKHWC);
				EditText etGZBCFYWC = (EditText) epointcompany_ccqk
						.findViewById(R.id.etGZBCFYWC);
				LinearLayout ll_fymx = (LinearLayout) epointcompany_ccqk
						.findViewById(R.id.ll_fymx);

				String bs = param[1].toString();
				etCCDQ.setText(StringHelp.cutLastSymbol(StringHelp.getXMLAtt(bs, "Area"), ";"));
				etCCXXDZ.setText(StringHelp.getXMLAtt(bs, "Address"));
				etCCQZSJ.setText(StringHelp.getXMLAtt(bs, "StartTime") + " 至 "
						+ StringHelp.getXMLAtt(bs, "EndTimte"));
				etSYCL.setText(StringHelp.getXMLAtt(bs, "IsUseCar").equals("1") ? "是"
						: "否");
				String ccsj = "";
				if (getIntent().getStringExtra("chuchaisj").equals("1")) {
					ccsj = "半天";
				} else if (getIntent().getStringExtra("chuchaisj").equals("2")) {
					ccsj = "一天";
				}
				etCCSJ.setText(ccsj);

				etYCRYZC.setText(StringHelp.getXMLAtt(bs, "YCPartners"));
				etYCKHZC.setText(StringHelp.getXMLAtt(bs, "YCCustomers"));
				etGZBCFYZC.setText(StringHelp.getXMLAtt(bs, "GZBCMoney") + "元");
				etYCRYWC.setText(StringHelp.getXMLAtt(bs, "YCPartnersPMName"));
				etYCKHWC.setText(StringHelp.getXMLAtt(bs, "YCCustomersPM"));
				etGZBCFYWC.setText(StringHelp.getXMLAtt(bs, "GZBCMoneyPM")
						+ "元");

				String wcbt = StringHelp.getXMLAtt(bs, "IsNeedWCMoney");
				String zsbt = StringHelp.getXMLAtt(bs, "IsNeedZSMoney");
				String bt = "";

				if (wcbt.equals("1")) {
					bt += "误餐补贴";
				}
				if (zsbt.equals("1")) {
					if (bt.length() > 0) {
						bt += "+住宿补贴";
					} else {
						bt += "住宿补贴";
					}
				}

				etBT.setText(bt);

				String fymx_xml = StringHelp.getXMLAttOut(bs, "fymxs");

				List<GongzuoRzBaoxiaoModel> bxlist = GetCCQKTask
						.XmlAnalysis(fymx_xml);

				if (bxlist.size() > 0) {
					LinearLayout xfmx_title_ll = (LinearLayout) inflater
							.inflate(R.layout.fymx_ll, null);
					TextView tvXH = (TextView) xfmx_title_ll
							.findViewById(R.id.tvXH);
					TextView tvFYLB = (TextView) xfmx_title_ll
							.findViewById(R.id.tvFYLB);
					TextView tvBXJE = (TextView) xfmx_title_ll
							.findViewById(R.id.tvBXJE);
					TextView tvFSD = (TextView) xfmx_title_ll
							.findViewById(R.id.tvFSD);
					tvXH.setText(Html.fromHtml("<font color="+getYGColor()+">序号</font>"));
					tvFYLB.setText(Html
							.fromHtml("<font color="+getYGColor()+">费用类别</font>"));
					tvBXJE.setText(Html
							.fromHtml("<font color="+getYGColor()+">报销金额</font>"));
					tvFSD.setText(Html
							.fromHtml("<font color="+getYGColor()+">发生地</font>"));
					ll_fymx.addView(xfmx_title_ll);
				}
				for (int i = 0; i < bxlist.size(); i++) {
					final GongzuoRzBaoxiaoModel grbx = bxlist.get(i);
					LinearLayout xfmx_title_ll = (LinearLayout) inflater
							.inflate(R.layout.fymx_ll, null);

					TextView tvXH = (TextView) xfmx_title_ll
							.findViewById(R.id.tvXH);
					TextView tvFYLB = (TextView) xfmx_title_ll
							.findViewById(R.id.tvFYLB);
					TextView tvBXJE = (TextView) xfmx_title_ll
							.findViewById(R.id.tvBXJE);
					TextView tvFSD = (TextView) xfmx_title_ll
							.findViewById(R.id.tvFSD);
					setTextViewFontColor(tvXH);
					setTextViewFontColor(tvFYLB);
					setTextViewFontColor(tvBXJE);
					setTextViewFontColor(tvFSD);
					tvXH.setText(grbx.xh);
					tvFYLB.setText(grbx.BXTypeStr);
					tvBXJE.setText(grbx.BXMoney);
					tvFSD.setText(StringHelp.cutLastSymbol(grbx.FaShengDi, ";"));
					xfmx_title_ll.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							AlertHelp.ShowAlert(RZTianxieView.this, "【序号】"
									+ grbx.xh + "\n【费用类别】" + grbx.BXMoney
									+ "\n【报销金额】" + grbx.BXMoney + "\n【发生地】"
									+ grbx.FaShengDi + "\n【备注】" + grbx.Remarks);
						}
					});
					ll_fymx.addView(xfmx_title_ll);
				}

				rl_rizhidetail.addView(epointcompany_ccqk);
			} else if (taskid == 3) {

				String bs = param[1].toString();
				etWorkThink.setText(StringHelp.getXMLAtt(bs, "experience"));
				String startworktime = StringHelp
						.getXMLAtt(bs, "startworktime");
				String endworktime = StringHelp.getXMLAtt(bs, "endworktime");
				String IsAddXinDeToBlog = StringHelp.getXMLAtt(bs,
						"IsAddXinDeToBlog");

				if (IsAddXinDeToBlog.equals("1")) {
					cbAdd2Blog.setChecked(true);
				}
				for (int i = 0; i < sj.length; i++) {
					if (sj[i].equals(startworktime)) {
						spfrom.setSelection(i);
					}
				}

				for (int i = 0; i < sj.length; i++) {
					if (sj[i].equals(endworktime)) {
						spto.setSelection(i);
					}
				}

				String rwbs = StringHelp.getXMLAttOut(bs, "gzmxs");

				gzrzdlist = GetRZTXInfo.XmlAnalysis(rwbs);
				DRGZMXAdapter adapter = new DRGZMXAdapter();
				drgzmxlv.setAdapter(adapter);
				drgzmxlv.setOnItemClickListener(new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							int position, long id) {
						AlertHelp.AlertWithTextView2(
								RZTianxieView.this,
								"<font color=yellow>工作内容:</font>"
										+ gzrzdlist.get(position).GongZuoNR);
					}
				});
			} else if (taskid == 4) {
				String bs = param[1].toString();
				if (bs.contains("<Result>True</Result>")) {
					ToastHelp.showToast(this, "保存成功");
					gzrzguid = StringHelp.getXMLAtt(bs, "RZRowGuid");
					taskid = 5;
					top_pb.setVisibility(View.VISIBLE);
					HashMap<String, Object> params = new HashMap<String, Object>();
					params.put("rzguid", gzrzguid);
					params.put("ccguid", ccguid);
					Task task = new GetChuchaibaoxiaomingxiTask(this, params);
					MainService.addTask(task);
				} else {
					ToastHelp.showToast(this, "保存失败");
				}
			} else if (taskid == 5) {
				final String bs = param[1].toString();

				addresscode = StringHelp.getXMLAtt(bs, "Address");
				addressname = StringHelp.getXMLAtt(bs, "AddressName");

				String ccsj = StringHelp.getXMLAtt(bs, "chuchaisj");
				String wcbt = StringHelp.getXMLAtt(bs, "wcbt");
				String zsbt = StringHelp.getXMLAtt(bs, "zsbt");
				String ycrynames_zc = StringHelp.getXMLAtt(bs, "ycrynames_zc");
				String ycryguids_zc = StringHelp.getXMLAtt(bs, "ycryguids_zc");
				String ycrynames_wc = StringHelp.getXMLAtt(bs, "ycrynames_wc");
				String ycryguids_wc = StringHelp.getXMLAtt(bs, "ycryguids_wc");
				String ycrycustomer_zc = StringHelp.getXMLAtt(bs,
						"ycrycustomer_zc");
				String ycrycustomer_wc = StringHelp.getXMLAtt(bs,
						"ycrycustomer_wc");
				String ycfy_zc = StringHelp.getXMLAtt(bs, "ycfy_zc");
				String ycfy_wc = StringHelp.getXMLAtt(bs, "ycfy_wc");

				if (ccsj.equals("2")) {
					spCcsj.setSelection(1);
				}
				if (wcbt.equals("1")) {
					cbWcbt.setChecked(true);
				}
				if (zsbt.equals("1")) {
					cbZsbt.setChecked(true);
				}

				ycpersonnames_zc = ycrynames_zc;
				ycpersonguids_zc = ycryguids_zc;
				ycpersonnames_wc = ycrynames_wc;
				ycpersonguids_wc = ycryguids_wc;
				etYcry_zc.setText(ycpersonnames_zc);
				etYcry_wc.setText(ycpersonnames_wc);
				etYckh_zc.setText(ycrycustomer_zc);
				etYckh_wc.setText(ycrycustomer_wc);
				etYcfy_zc.setText(ycfy_zc);
				etYcfy_wc.setText(ycfy_wc);

				String liststr = StringHelp.getXMLAttOut(bs, "ccfys");
				bxmxlist = GetChuchaibaoxiaomingxiTask.XmlAnalysis(liststr);
				BXMXAdapter adapter = new BXMXAdapter();
				lvBxmx.setAdapter(adapter);
				lvBxmx.setOnItemLongClickListener(new OnItemLongClickListener() {

					@Override
					public boolean onItemLongClick(AdapterView<?> parent,
							View view, int position, long id) {

						final int myposition = position;
						AlertHelp.showAlertMenu(RZTianxieView.this, "操作",
								new String[] { "删除" },
								new DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										String rowguid = bxmxlist
												.get(myposition).RowGuid;
										if (which == 0) {
											if (bxmxlist.get(myposition).BXTypeName
													.equals("误餐补贴")
													|| bxmxlist.get(myposition).BXTypeName
															.equals("住宿补贴")) {
												ToastHelp
														.showToast(
																RZTianxieView.this,
																"勾去误餐或住宿补贴后点击保存，即可删除误餐和住宿补贴条目");
												return;
											}
											taskid = 8;
											showDialog_wait("正在删除...");
											HashMap<String, Object> map = new HashMap<String, Object>();
											map.put("rowguid", rowguid);
											Task task = new DeleteBaoxiaomingxiTask(
													RZTianxieView.this, map);
											MainService.addTask(task);
										}
									}
								});

						return false;
					}
				});

			} else if (taskid == 6) {
				String bs = param[1].toString();
				if (bs.contains("<Result>True</Result>")) {
					ToastHelp.showToast(this, "日志提交成功");
					String backrzguid = StringHelp.getXMLAtt(bs, "RZRowGuid");
					if (!backrzguid.equals("") && gzrzguid.equals("")) {
						gzrzguid = backrzguid;
					}

				} else {
					ToastHelp.showToast(this, "日志提交失败");
				}
			} else if (taskid == 7) {
				String bs = param[1].toString();
				if (bs.contains("<Result>True</Result>")) {
					ToastHelp.showToast(this, "日志保存成功");
					String backrzguid = StringHelp.getXMLAtt(bs, "RZRowGuid");
					if (!backrzguid.equals("") && gzrzguid.equals("")) {
						gzrzguid = backrzguid;
					}
				} else {
					ToastHelp.showToast(this, "日志保存失败");
				}
			} else if (taskid == 8) {
				String bs = param[1].toString();
				if (bs.contains("<result>1</result>")) {
					ToastHelp.showToast(this, "删除成功");
					taskid = 5;
					top_pb.setVisibility(View.VISIBLE);
					HashMap<String, Object> params = new HashMap<String, Object>();
					params.put("rzguid", gzrzguid);
					params.put("ccguid", ccguid);
					Task task = new GetChuchaibaoxiaomingxiTask(this, params);
					MainService.addTask(task);
				} else {
					ToastHelp.showToast(this, "删除失败");
				}
			}
		}
	}

	private Button btAddNewJob, btRZSubmit, btRZSave;
	private EditText etWorkThink;
	private Spinner spfrom;
	private Spinner spto;
	private TextView tvgzsj;
	private CheckBox cbAdd2Blog;

	private void gzrizhitianxie() {

		/*
		 * top_right_bt.setVisibility(View.VISIBLE);
		 * top_right_bt.setBackgroundResource(R.drawable.btn_top_save);
		 * top_right_bt.setOnClickListener(this);
		 */

		top_title.setText("工作日志填写");
		rl_rizhidetail.removeAllViews();

		epoint_gzrztx = (RelativeLayout) inflater.inflate(
				R.layout.epoint_gzrztx, null);

		tvgzsj = (TextView) epoint_gzrztx.findViewById(R.id.tvgzsj);
		etWorkThink = (EditText) epoint_gzrztx.findViewById(R.id.etWorkThink);
		btRZSubmit = (Button) epoint_gzrztx.findViewById(R.id.btRZSubmit);
		btRZSave = (Button) epoint_gzrztx.findViewById(R.id.btRZSave);
		cbAdd2Blog = (CheckBox) epoint_gzrztx.findViewById(R.id.cbAdd2Blog);
		btRZSubmit.setOnClickListener(this);
		btRZSave.setOnClickListener(this);
		tvgzsj.setText(rzdate.substring(0, 10));
		spfrom = (Spinner) epoint_gzrztx.findViewById(R.id.spgzsjfrom);
		ArrayAdapter<String> aafrom = ControlsHelp.getSPAdapter(this);
		for (String s : sj) {
			aafrom.add(s);
		}
		spfrom.setAdapter(aafrom);

		spto = (Spinner) epoint_gzrztx.findViewById(R.id.spgzsjto);
		spto.setAdapter(aafrom);

		spfrom.setSelection(16);
		spto.setSelection(34);

		btAddNewJob = (Button) epoint_gzrztx.findViewById(R.id.btAddNewJob);
		btAddNewJob.setOnClickListener(this);

		drgzmxlv = (ListView) epoint_gzrztx.findViewById(R.id.lvGzmx);

		rl_rizhidetail.addView(epoint_gzrztx);
		if (gzrzguid.trim().length() > 0) {
			showDialog_wait(null);
			taskid = 3;
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("rzdate", rzdate);
			params.put("rzguid", gzrzguid);
			Task task = new GetRZTXInfo(this, params);
			MainService.addTask(task);
		}
	}

	private Spinner spCcsj;
	private Button btYcry_zc, btYcry_wc, btTjqtfy;
	private String ycpersonnames_zc = "";
	private String ycpersonguids_zc = "";
	private String ycpersonnames_wc = "";
	private String ycpersonguids_wc = "";
	private EditText etYcry_zc, etYcfy_zc, etYcry_wc, etYcfy_wc, etYckh_zc,
			etYckh_wc;
	private CheckBox cbWcbt, cbZsbt;
	private TextView tvTip, tvSaveWarning;
	private ListView lvBxmx;
	private List<ChuchaibaoxiaomingxiModel> bxmxlist;

	// 当日费用
	private void drfy() {
		rl_rizhidetail.removeAllViews();
		RelativeLayout epoint_drfy = (RelativeLayout) inflater.inflate(
				R.layout.epoint_drfy, null);

		spCcsj = (Spinner) epoint_drfy.findViewById(R.id.spCcsj);
		cbWcbt = (CheckBox) epoint_drfy.findViewById(R.id.cbWcbt);
		cbZsbt = (CheckBox) epoint_drfy.findViewById(R.id.cbZsbt);
		setTextViewFontColor(cbWcbt);
		setTextViewFontColor(cbZsbt);
		btYcry_zc = (Button) epoint_drfy.findViewById(R.id.btYcry_zc);
		btYcry_wc = (Button) epoint_drfy.findViewById(R.id.btYcry_wc);
		btTjqtfy = (Button) epoint_drfy.findViewById(R.id.btTjqtfy);
		Button btSave = (Button) epoint_drfy.findViewById(R.id.btSave);
		btYcry_zc.setOnClickListener(this);
		btYcry_wc.setOnClickListener(this);
		btTjqtfy.setOnClickListener(this);
		etYcfy_zc = (EditText) epoint_drfy.findViewById(R.id.etFy_zc);
		etYcfy_wc = (EditText) epoint_drfy.findViewById(R.id.etFy_wc);
		etYckh_zc = (EditText) epoint_drfy.findViewById(R.id.etYckh_zc);
		etYckh_wc = (EditText) epoint_drfy.findViewById(R.id.etYckh_wc);
		tvSaveWarning = (TextView) epoint_drfy.findViewById(R.id.tvSaveWarning);
		lvBxmx = (ListView) epoint_drfy.findViewById(R.id.lvBxmx);
		if ((serverDateInt - clickdate) >= 3) {
			tvSaveWarning.setVisibility(View.VISIBLE);
			btSave.setEnabled(false);
			btTjqtfy.setEnabled(false);
		}
		btSave.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showDialog_wait("正在保存数据...");
				taskid = 4;
				HashMap<String, Object> param = new HashMap<String, Object>();
				param.put("RZRowGuid", gzrzguid);

				System.out.println(rzdate);
				param.put("RZDate", rzdate);

				String ccsjflag = "1";
				if (spCcsj.getSelectedItemPosition() == 1) {
					ccsjflag = "2";
				}

				param.put("ChuChaiSJ", ccsjflag);

				param.put("IsNeedWCMoney", cbWcbt.isChecked() ? "1" : "2");
				param.put("IsNeedZSMoney", cbZsbt.isChecked() ? "1" : "2");

				String IsNeedBCAM = "0";
				if (etYcry_zc.getText().toString().trim().length() > 0
						&& !etYcfy_zc.getText().toString().equals("0")) {
					IsNeedBCAM = "1";
				}
				param.put("IsNeedBCAM", IsNeedBCAM);

				String IsNeedBCPM = "0";
				if (etYcry_wc.getText().toString().trim().length() > 0
						&& !etYcfy_wc.getText().toString().equals("0")) {
					IsNeedBCPM = "1";
				}
				param.put("IsNeedBCPM", IsNeedBCPM);
				param.put("AMUserNames", ycpersonnames_zc);
				param.put("AMUserGuids", ycpersonguids_zc);
				param.put("AMCustomers", etYckh_zc.getText().toString());
				param.put("AMMoney",
						etYcfy_zc.getText().toString().equals("") ? "0"
								: etYcfy_zc.getText().toString());
				param.put("PMUserNames", ycpersonnames_wc);
				param.put("PMUserGuids", ycpersonguids_wc);
				param.put("PMCustomers", etYckh_wc.getText().toString());
				param.put("PMMoney",
						etYcfy_wc.getText().toString().equals("") ? "0"
								: etYcfy_wc.getText().toString());
				Task task = new BtnAddBaoxiaoDetailTask(RZTianxieView.this,
						param);
				MainService.addTask(task);
			}
		});

		tvTip = (TextView) epoint_drfy.findViewById(R.id.tvTip);
		etYcry_zc = (EditText) epoint_drfy.findViewById(R.id.etYcry_zc);
		etYcry_wc = (EditText) epoint_drfy.findViewById(R.id.etYcry_wc);

		tvTip.setText("提示：误餐补贴请直接在\"费用补贴--误餐补贴\"一栏勾选，不需在工作便餐中填写！");
		ArrayAdapter<String> accsj = ControlsHelp.getSPAdapter(this);
		String[] s_ccsj = new String[] { "半天", "一天" };
		for (String s : s_ccsj) {
			accsj.add(s);
		}

		spCcsj.setAdapter(accsj);

		rl_rizhidetail.addView(epoint_drfy);

		String rzguid = gzrzguid == null ? "" : gzrzguid;

		if (rzguid.length() > 0) {
			taskid = 5;
			showDialog_wait(null);
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("rzguid", gzrzguid);
			params.put("ccguid", ccguid);
			Task task = new GetChuchaibaoxiaomingxiTask(this, params);
			MainService.addTask(task);
		}
	}

	// 旅游情况
	private void lyqk() {
		// rl_rizhidetail.removeAllViews();
	}

	@Override
	public int getLayoutInt() {
		return R.layout.epointcompany_rizitianxieview;
	}

	@Override
	public void onClick(View v) {
		if (v == btRznr) {
			Rizineirong();
		} else if (v == btDrfy) {
			drfy();
		} else if (v == btLyqk) {
			lyqk();
		} else if (v == btQjqk) {
			qjqk();
		} else if (v == btCcqk) {
			ccqk();
		} else if (v == btGzlr) {
			gzrizhitianxie();
		} else if (v == btYcry_zc) {
			resumeType = 1;
			PersonChooseViewNew.clist = StringHelp.String2List(
					ycpersonnames_zc, ycpersonguids_zc);
			Intent it = new Intent(this, PersonChooseViewNew.class);
			startActivity(it);
		} else if (v == btYcry_wc) {
			resumeType = 2;
			PersonChooseViewNew.clist = StringHelp.String2List(
					ycpersonnames_wc, ycpersonguids_wc);
			Intent it = new Intent(this, PersonChooseViewNew.class);
			startActivity(it);
		} else if (v == btTjqtfy) {
			resumeType = 4;
			Intent it = new Intent(this, AddFeiyongbaoxiaoDetailView.class);
			it.putExtra("rzdate", rzdate);
			it.putExtra("rzguid", gzrzguid);
			it.putExtra("addressname", addressname);
			it.putExtra("addresscode", addresscode);
			startActivity(it);
		} else if (v == btAddNewJob) {
			resumeType = 3;
			Intent it = new Intent(RZTianxieView.this,
					AddNewWorkContentView.class);
			it.putExtra("rzguid", gzrzguid);
			it.putExtra("rzdate", rzdate);
			startActivity(it);
		} else if (v == btRZSubmit) {
			taskid = 6;
			showDialog_wait("正在提交日志...");
			HashMap<String, Object> param = new HashMap<String, Object>();
			param.put("rzguid", gzrzguid);
			param.put("rzdate", rzdate);
			Task task = new SummitRizhiTask(this, param);
			MainService.addTask(task);
		} else if (v == btRZSave) {
			taskid = 7;
			showDialog_wait("正在保存日志...");
			HashMap<String, Object> param = new HashMap<String, Object>();
			param.put("RZRowGuid", gzrzguid);
			param.put("RZDate", tvgzsj.getText().toString());
			param.put("StartWorkTime", spfrom.getSelectedItem().toString());
			param.put("EndWorkTime", spto.getSelectedItem().toString());
			String IsAddXinDeToBlog = "0";
			if (cbAdd2Blog.isChecked()) {
				IsAddXinDeToBlog = "1";
			}
			param.put("IsAddXinDeToBlog", IsAddXinDeToBlog);
			param.put("Experience", etWorkThink.getText().toString());
			param.put("BlogTitle", "工作心得");
			Task task = new SaveRizhiTask(this, param);
			MainService.addTask(task);
		}
	}
	
	@Override
	protected void onResume() {
		super.onResume();

		if (resumeType == 1) {
			String[] info = StringHelp
					.dealChooseListToString(PersonChooseViewNew.clist);
			ycpersonnames_zc = info[0];
			ycpersonguids_zc = info[1];
			etYcry_zc.setText(ycpersonnames_zc);
		} else if (resumeType == 2) {
			String[] info = StringHelp
					.dealChooseListToString(PersonChooseViewNew.clist);
			ycpersonnames_wc = info[0];
			ycpersonguids_wc = info[1];
			etYcry_wc.setText(ycpersonnames_wc);
		} else if (resumeType == 3) {
			if (AddNewWorkContentView.gzrzguid.length() > 0) {
				gzrzguid = AddNewWorkContentView.gzrzguid;
				showDialog_wait(null);
				taskid = 3;
				HashMap<String, Object> params = new HashMap<String, Object>();
				params.put("rzdate", rzdate);
				params.put("rzguid", gzrzguid);
				Task task = new GetRZTXInfo(this, params);
				MainService.addTask(task);
			}
		} else if (resumeType == 4) {
			if (AddFeiyongbaoxiaoDetailView.rzguid.length() > 0) {
				taskid = 5;
				showDialog_wait(null);
				gzrzguid = AddFeiyongbaoxiaoDetailView.rzguid;
				HashMap<String, Object> params = new HashMap<String, Object>();
				params.put("rzguid", gzrzguid);
				params.put("ccguid", ccguid);
				Task task = new GetChuchaibaoxiaomingxiTask(this, params);
				MainService.addTask(task);
			}
		}
	
	}


	class BXMXAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return bxmxlist.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				LayoutInflater mInflater = LayoutInflater
						.from(RZTianxieView.this);

				convertView = mInflater.inflate(
						R.layout.rztianxieviewmissionlist, null);

				holder.tvTop = (TextView) convertView.findViewById(R.id.tvtop);
				holder.tvMiddle = (TextView) convertView
						.findViewById(R.id.tvMiddle);
				holder.tvBottom = (TextView) convertView
						.findViewById(R.id.tvBottom);

				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.tvTop.setText(Html
					.fromHtml("<font color=#FFD306>费用类别:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ bxmxlist.get(position).BXTypeName
							+ "</font>&nbsp&nbsp"
							+ "<font color=#FFD306>发生地:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ bxmxlist.get(position).fsdnames + "</font>"));
			holder.tvMiddle.setText(Html
					.fromHtml("<font color=#FFD306>报销金额:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ bxmxlist.get(position).BXMoney + "</font>"));

			holder.tvBottom.setText(Html
					.fromHtml("<font color=#FFD306>备注:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ bxmxlist.get(position).Remark));
			return convertView;
		}
	}

	class DRGZMXAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return gzrzdlist.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				LayoutInflater mInflater = LayoutInflater
						.from(RZTianxieView.this);

				convertView = mInflater.inflate(
						R.layout.rztianxieviewmissionlist, null);

				holder.tvTop = (TextView) convertView.findViewById(R.id.tvtop);
				holder.tvMiddle = (TextView) convertView
						.findViewById(R.id.tvMiddle);
				holder.tvBottom = (TextView) convertView
						.findViewById(R.id.tvBottom);

				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.tvTop.setText(Html
					.fromHtml("<font color=#FFD306>类别:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ gzrzdlist.get(position).ContentTypeName
							+ "</font>&nbsp&nbsp"
							+ "<font color=#FFD306>项目名称:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ gzrzdlist.get(position).ProjectName + "</font>"));
			holder.tvMiddle.setText(Html
					.fromHtml("<font color=#FFD306>任务名称:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ gzrzdlist.get(position).MissionName + "</font>"));

			holder.tvBottom.setText(Html
					.fromHtml("<font color=#FFD306>工时:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ gzrzdlist.get(position).GongZuoSJ
							+ "</font>&nbsp&nbsp"
							+ "<font color=#FFD306>加班工时:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ gzrzdlist.get(position).ExtraWorkSJ
							+ "</font>&nbsp&nbsp"
							+ "<font color=#FFD306>比例:</font><font color='"
							+ getBlackOrWhiteColor() + "'>"
							+ gzrzdlist.get(position).CompletePercent
							+ "%</font>"));
			return convertView;
		}
	}

	public class ViewHolder {
		public TextView tvTop;
		public TextView tvMiddle;
		public TextView tvBottom;
	}

	@Override
	public void refreshForNewTask(int TaskId,Object... param){
	}

}
